package com.ran.asynctaskdemo;

import android.os.AsyncTask;
import android.widget.ProgressBar;
import android.widget.TextView;

/**
 * Created by Bruce on 2017/5/19.
 */

public class MyAsyncTask extends AsyncTask<Integer, Integer, String> {
    private TextView txt;
    private ProgressBar pgbar;

    public MyAsyncTask(TextView txt, ProgressBar pgbar) {
        super();
        this.txt = txt;
        this.pgbar = pgbar;
    }

    @Override
    protected String doInBackground(Integer... params) {
        DelayOperator dop = new DelayOperator();
        int i = 0;
        for (i = 10; i <= 100; i += 10) {
            dop.delay();
            publishProgress(i);
        }
        return i + params[0].intValue() + "";
    }

    @Override
    protected void onPreExecute() {
        txt.setText("开始执行异步任务...");
    }

    @Override
    protected void onProgressUpdate(Integer... values) {
        int value = values[0];
        pgbar.setProgress(value);
    }
}
